package com.LostAndFound.service;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import com.LostAndFound.dao.SearchForLoserDao;
import com.LostAndFound.domain.Article;
import com.LostAndFound.utils.DataSourceUtils;

public class SearchForLoserService {

	SearchForLoserDao dao = new SearchForLoserDao();
	
	public int getTotalRecordForEasyUI(String cid) {
		int total = 0;
		try {
			total = dao.getTotalRecordForEasyUI(cid);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return total;
	}
	// 得到要进行审核的记录数
	public int getCheckTotalRecordForEasyUI(String cid) {
		int total = 0;
		try {
			total = dao.getCheckTotalRecordForEasyUI(cid);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return total;
	}
	public List<Map<String, Object>> getRecordListForSearchLoserToEasyUI(int pageNumber, int pageSize, String cid) {
		List<Map<String, Object>> mapList = null;
		int startIndex = (pageNumber-1)*pageSize;
		
		try {
			mapList = dao.getRecordListForSearchLoserToEasyUI(startIndex,pageSize,cid);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return mapList;
	}
	// 得到要进行审核的记录
	public List<Map<String, Object>> getCheckRecordListForSearchLoserToEasyUI(int pageNumber, int pageSize, String cid) {
		List<Map<String, Object>> mapList = null;
		int startIndex = (pageNumber-1)*pageSize;
		
		try {
			mapList = dao.getCheckRecordListForSearchLoserToEasyUI(startIndex,pageSize,cid);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return mapList;
	}
	public boolean handleDeleteSearchLoserRecordForEasyUI(String aid) {
		boolean success = false;
		try {
			dao.handleDeleteSearchLoserRecordForEasyUI(aid);
			success = true;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return success;
	}

	/*
	 * 隐藏此功能，2019/03/03
	 */
	public boolean handleAddNewSearchLoser(Article article) {
		boolean success = false;
		try {
			DataSourceUtils.startTransaction();
			dao.handleAddNewSearchLoser(article);
			success = true;
		} catch (SQLException e) {
			try {
				DataSourceUtils.rollback();
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				DataSourceUtils.commitAndRelease();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return success;
	}

}
